from fastapi import Depends, APIRouter
from fastapi.security import OAuth2PasswordBearer
from dao.redis_dao.token_dao import get_depart_authority
from service.health_service import find_health_log, get_exception_count

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
health_router = APIRouter(prefix='/test/wristband', tags=['手环', '健康数据'])


@health_router.post("/health_log")
async def handle(data: dict) -> dict:
    result = await find_health_log(data)
    return {"status": 1, "result": result}


@health_router.post("/exception_count")
async def health_exception_count(data: dict, token: str = Depends(oauth2_scheme)):
    """获取异常数量"""
    depart: list = data.get('departId')
    if depart is None:
        depart = await get_depart_authority(token)
    result = await get_exception_count(data, depart)
    return {
        "code": 200,
        "success": True,
        "message": "操作成功",
        "data": {
            "result": result
        }
    }